package com.block.common.mq;

import com.alibaba.fastjson.JSON;
import com.block.common.constant.MqConstant;
import com.block.common.exception.NotifyExceptionService;
import com.block.common.model.dto.SourceCountDTO;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

@Service
public class MqSourceCountSendService {

    @Autowired
    NotifyExceptionService notifyExceptionService;

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Async
    public void sourceDataCountSend(SourceCountDTO sourceCountDTO){

        try {
            String content = JSON.toJSONString(sourceCountDTO);
            Message message = new Message(content.getBytes());
            this.rabbitTemplate.send(MqConstant.Exchange.LAIQIANBA_SOURCE, MqConstant.KEY.SOURCE_COUNT_KEY, message);
            System.out.println("Message sent successfully================ " + content);
        }catch (Exception exception){
            exception.printStackTrace();
            notifyExceptionService.notifyNoticeInfo("MQ_SEND_EXCE", "线索统计发送异常", JSON.toJSONString(sourceCountDTO), exception);
        }
    }
}
